package com.ruoyi.schedule.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.schedule.domain.vo.TaskinfoLogsVo;
import com.ruoyi.schedule.domain.bo.TaskinfoLogsBo;
import com.ruoyi.schedule.service.ITaskinfoLogsService;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;

import java.util.List;
import java.util.Arrays;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.servlet.http.HttpServletResponse;

/**
 * 【请填写功能名称】控制器
 * 前端访问路由地址为:/schedule/logs
 *
 * @author xiaoqiang
 * @date 2022-11-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/logs")
public class TaskinfoLogsController extends BaseController {

    private final ITaskinfoLogsService iTaskinfoLogsService;

    /**
     * 查询【请填写功能名称】列表
     */
    @SaCheckPermission("schedule:logs:list")
    @GetMapping("/list")
    public TableDataInfo<TaskinfoLogsVo> list(TaskinfoLogsBo bo, PageQuery pageQuery) {
        return iTaskinfoLogsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @SaCheckPermission("schedule:logs:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TaskinfoLogsBo bo, HttpServletResponse response) {
        List<TaskinfoLogsVo> list = iTaskinfoLogsService.queryList(bo);
        ExcelUtil.exportExcel(list, "【请填写功能名称】", TaskinfoLogsVo.class, response);
    }

    /**
     * 获取【请填写功能名称】详细信息
     *
     * @param taskId 主键
     */
    @SaCheckPermission("schedule:logs:query")
    @GetMapping("/{taskId}")
    public R<TaskinfoLogsVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long taskId) {
        return R.ok(iTaskinfoLogsService.queryById(taskId));
    }

    /**
     * 新增【请填写功能名称】
     */
    @SaCheckPermission("schedule:logs:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TaskinfoLogsBo bo) {
        return toAjax(iTaskinfoLogsService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改【请填写功能名称】
     */
    @SaCheckPermission("schedule:logs:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TaskinfoLogsBo bo) {
        return toAjax(iTaskinfoLogsService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除【请填写功能名称】
     *
     * @param taskIds 主键串
     */
    @SaCheckPermission("schedule:logs:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{taskIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] taskIds) {
        return toAjax(iTaskinfoLogsService.deleteWithValidByIds(Arrays.asList(taskIds), true) ? 1 : 0);
    }
}
